package tas.co.in.controller.employeeInfo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import tas.co.in.dao.employeeInfo.EmployeeInfo;
import tas.co.in.domain.employeeInfo.EmployeeInfoBean;

public class EmployeeInfoController extends MultiActionController 
{
	private EmployeeInfo employeeInfo;

	public void setEmployeeInfo(EmployeeInfo employeeInfo) 
	{
		this.employeeInfo = employeeInfo;
	}
	
	public ModelAndView setEmployeeRole(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession(true);

		EmployeeInfoBean bean = new EmployeeInfoBean();
		bean.setUserID(session.getAttribute("userId").toString());
		bean.setUserName(session.getAttribute("userName").toString());
		bean.setEmpName(request.getParameter("empName"));
		bean.setGender(request.getParameter("gender"));
		bean.setDob(request.getParameter("dob"));
		bean.setAddress(request.getParameter("add"));
		bean.setCountry(request.getParameter("country"));
		bean.setState(request.getParameter("state"));
		bean.setCity(request.getParameter("city"));
		bean.setArea(request.getParameter("area"));
		bean.setImgPath(request.getParameter("imgPath"));
		bean.setPhNumber(request.getParameter("phNo"));
		bean.setEmail(request.getParameter("email"));
		bean.setRoleID(request.getParameter("roleId"));
		
		boolean resultObject = employeeInfo.setEmployeeInfo(bean);
		return new ModelAndView("sharedJSP/BooleanResults", "resultObject", resultObject);
	}
	
	public ModelAndView getEmployeeDetail(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession(true);
		EmployeeInfoBean bean = new EmployeeInfoBean();
		bean.setUserID(session.getAttribute("userId").toString());
		bean.setUserName(session.getAttribute("userName").toString());
		
		List<EmployeeInfoBean> resultObject = employeeInfo.getDetails(bean);
				
		return new ModelAndView("sharedJSP/getEmployeeDetail", "resultObject", resultObject);
	}
	
	public ModelAndView updateEmpDetail(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession(true);
		EmployeeInfoBean bean = new EmployeeInfoBean();
		bean.setUserID(session.getAttribute("userId").toString());
		bean.setUserName(session.getAttribute("userName").toString());
		bean.setEmpID(request.getParameter("empID"));
		bean.setEmpName(request.getParameter("empName"));
		bean.setDob(request.getParameter("dob"));
		bean.setAddress(request.getParameter("address"));
		bean.setCountry(request.getParameter("country"));
		bean.setState(request.getParameter("state"));
		bean.setCity(request.getParameter("city"));
		bean.setArea(request.getParameter("area"));
		bean.setImgPath(request.getParameter("imgPath"));
		bean.setPhNumber(request.getParameter("phoneNumber"));
		bean.setEmail(request.getParameter("email"));
		
		boolean resultObject = employeeInfo.updateEmployeeDetail(bean);
		return new ModelAndView("sharedJSP/BooleanResults", "resultObject", resultObject);
	}
}
